#ifndef _AS_SINGLETON_H_
#define _AS_SINGLETON_H_

#include "ASCommon.h"

NS_AS_BEGIN

template<class T>
class ASSingleton
{
public:
	static T* Instance()
	{
		if(!_instance)
			_instance = new T;
		return _instance;
	};
	void Release()
	{
		if(!_instance)
			return;
		delete _instance;
		_instance = nullptr;
	};
	
protected:
	ASSingleton(void){};
	//virtual ~ASSingleton(void){};
	//copy ctor and assignment should be private
	ASSingleton(const ASSingleton& instance)
	{
		_instance = instance._instance;
	};
	ASSingleton& operator=(const ASSingleton& instance)
	{
		_instance = instance._instance;
	}
private:
	static T* _instance;
};
//
//
//template<class T>
//void ASSingleton<T>::release()
//{
//	if(!_instance)
//		return;
//	delete _instance;
//	_instance = nullptr;
//}


#define DECLARE_SINGLETON_MEMBER(_T) template<> _T* ASSingleton<_T>::_instance = nullptr;

NS_AS_END

#endif